import router from "@/router";
import { useUserStore } from "@/store/user";

export function logout(before?: () => void, after?: () => void) {
  const store = useUserStore();
  // token过期
  // 让用户出现登录，和退出登录的逻辑一样
  before && before();
  // 1.清除token
  localStorage.removeItem("token");
  //2.清空路由
  store.routes.forEach((item) => router.removeRoute(item.name));
  //3.清空pinia
  store.username = "";
  store.menus = [];
  //4.跳转到1ogin
  router.push("/login");
  //   调用callback
  after && after();
}
